#include "BuildEventTimeline.h"

#include "BuildUnitManager.h"
#include "..\Util.h"

namespace BroodWar
{
	namespace Addon
	{
		BuildEventTimeline::BuildEventTimeline(BWSAL::BuildEventTimeline* timeline)
		{
			instance = timeline;
		}

		BuildEventTimeline::~BuildEventTimeline()
		{
			BWSAL::BuildEventTimeline::destroy();
		}

		BuildEventTimeline::!BuildEventTimeline()
		{
			BWSAL::BuildEventTimeline::destroy();
		}

		void BuildEventTimeline::Create(IBuildUnitManager^ buildUnitManager)
		{
			BuildUnitManager^ manager = DirectCast<BuildUnitManager^>(buildUnitManager);
			BWSAL::BuildEventTimeline::destroy();
			s_instance = gcnew BuildEventTimeline(BWSAL::BuildEventTimeline::create(manager->instance));
		}
		
		BuildEventTimeline^ BuildEventTimeline::Instance::get()
		{
			return s_instance;
		}

		void BuildEventTimeline::Initialize()
		{
			instance->initialize();
		}
		
		void BuildEventTimeline::Draw()
		{
			instance->draw();
		}
		
		void BuildEventTimeline::DrawLarvaCounts()
		{
			instance->drawLarvaCounts();
		}
		
		void BuildEventTimeline::AddEvent(int time, BuildEvent^ e)
		{
			instance->addEvent(time, ConvertBuildEvent(e));
		}
		
		void BuildEventTimeline::Reset()
		{
			instance->reset();
		}
		
		BuildState^ BuildEventTimeline::InitialState::get()
		{
			return ConvertBuildState(instance->m_initialState);
		}

		void BuildEventTimeline::InitialState::set(BuildState^ value)
		{
			instance->m_initialState = ConvertBuildState(value);
		}

		String^ BuildEventTimeline::ToString()
		{
			return gcnew String(instance->toString().c_str());
		}
			
		IEnumerator<Tuple<int, BuildEvent^>^>^ BuildEventTimeline::GetEnumerator()
		{
			#pragma warning implement
			throw gcnew NotImplementedException();
		}

		System::Collections::IEnumerator^ BuildEventTimeline::GetEnumerator2()
		{
			return GetEnumerator();
		}
	}
}

/*
#pragma once
#include <list>
#include <BWSAL/BuildType.h>
#include <BWSAL/BuildEvent.h>
#include <BWSAL/BuildState.h>
#include <BWSAL/Types.h>
namespace BWSAL
{
  class BuildUnitManager;
  class BuildEventTimeline : public BWAPI::AIModule
  {
    public:
      static BuildEventTimeline* create( BuildUnitManager* buildUnitManager );
      static BuildEventTimeline* getInstance();
      static void destroy();
      void initialize();
      void draw();
      void drawLarvaCounts();
      std::list< std::pair< int, BuildEvent > >::iterator addEvent( int time, BuildEvent &e );
      std::list< std::pair< int, BuildEvent > >::iterator addEvent( int time, BuildEvent &e, std::list< std::pair< int, BuildEvent > >::iterator startSearchAt );
      std::list< std::pair< int, BuildEvent > >::iterator begin();
      std::list< std::pair< int, BuildEvent > >::iterator end();
      std::string toString() const;
      void reset();
      BuildState m_initialState;

    private:
      BuildEventTimeline();
      ~BuildEventTimeline();
      int m_finalSupplyUsed;
      int m_finalSupplyTotal;
      std::list< std::pair< int, BuildEvent > > m_events;
      BuildUnitManager* m_buildUnitManager;
      static BuildEventTimeline* s_buildEventTimeline;
  };
}
*/